package com.vip.eshop.inventory.request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Request Queue
 * Created by leo.song on 2017/8/25.
 */
public class RequestQueue {
    //Thread Queue
    private static List<ArrayBlockingQueue<Request>> queues = new ArrayList<ArrayBlockingQueue<Request>>();

    /**
     * 标识位map
     */
    private Map<Integer, Boolean> flagMap = new ConcurrentHashMap<Integer, Boolean>();

    public static void init() {
        getInstance();
    }

    public ArrayBlockingQueue<Request> getQueue(int index) {
        return queues.get(index);
    }

    private static class Singleton  {
        private static RequestQueue instance;

        static {
            instance = new RequestQueue();
        }

        public  static RequestQueue getInstance() {
            return instance;
        }
    }

    public static RequestQueue getInstance() {
        return Singleton.getInstance();
    }

    public void addQueue(ArrayBlockingQueue<Request> queue) {
        queues.add(queue);
    }

    public int queueSize() {
        return queues.size();
    }

    public Map<Integer, Boolean> getFlagMap() {
        return flagMap;
    }
}
